package com.pumpkin.web.busi.dao;

import com.pumpkin.web.model.UserModel;
import org.springframework.stereotype.Repository;

import java.util.*;

/**
 * (description)
 *
 * @author jinlong.liao on 2016/7/7
 */
@Repository
public class UserDao {

    private static Map<Integer, UserModel> userMap = Collections.synchronizedMap(new HashMap<Integer, UserModel>());

    public List<UserModel> queryList() {
        return new ArrayList<>(userMap.values());
    }

    public UserModel queryById(Integer id) {
        return userMap.get(id);
    }

    public void add(UserModel userModel) {
        int id = userMap.size() + 1;
        userModel.setId(id);
        userMap.put(id, userModel);
    }

    public void update(UserModel userModel) {
        userMap.put(userModel.getId(), userModel);
    }

    public void delete(Integer id) {
        userMap.remove(id);
    }
}
